package blackBoxTesting;

import org.junit.Test;

import data.ForumServer;

import data.ForumMessage;

public class ServerTests extends serverParsing{
  
	@Test
	public void testServerLoginLogoutRegistration() {
		//check correctness of user name and password, 

		
		//should be false - wrong password
		assertEquals("login\1guest\1failed\1wrong user or password\1\n\0", super.serverParsingTest("login\1tamir\1pass\n\0\n"));
		
		//should success - login with new user
		assertEquals("Register\1member\1success\1\n\0", super.serverParsingTest("register\1tamir\1pass\n\0\n"));
		
		//should success - logout with user
		assertEquals("logout\1\n\0", super.serverParsingTest("logout\1tamir\1pass\n\0\n"));
		
		//should fail - wrong format
		assertEquals("wrong format\1\n\0", super.serverParsingTest("login\1tamir\n\0\n"));
		
		
		//try to register with guest - should be failed
		assertEquals("Register\1guest\1failed\1user name allready exist\1\n\0", super.serverParsingTest("register\1guest\1pass\n\0\n"));


		//missed password - should be failed
		assertEquals("wrong format\1\n\0", super.serverParsingTest("login\1tamir\n\0\n"));
		

	}


	@Test
	public void testServerOfMessages() {
		ForumServer fs = new ForumServer();
		
		//view forum - as default we have a sport and music forums
		assertEquals("subForumList\1guest\1"+"1:sport\1"+"2:music\1\n\0", super.serverParsingTest("viewForum\1\0\n"));
		
		//sub forums are empty - should show a threads list

		assertEquals("ThreadsList\1guest\1\n\0", super.serverParsingTest("viewSubForum\1"+"guest\1"+"1\1"));
		
		//music
		assertEquals("ThreadsList\1guest\1\n\0", super.serverParsingTest("viewSubForum\1"+"guest\1"+"2\1"));
		
		//wrong numbers of arguments - should be failed
		assertEquals("wrong format ViewSubForumMessage\n\0", super.serverParsingTest("viewSubForum\1"+"guest\1"+"2\1"+"1\1"));
		
		//wrong choice of sub forum - should be failed
		assertEquals("wrong format ViewSubForumMessage\n\0", super.serverParsingTest("viewSubForum\1"+"guest\1"+"5\1"));
		
		//add threads
		
		
		//should fail - user not in System
		assertEquals("user dosen't exist in the system\n\0", super.serverParsingTest("addThread\1"+"amit\1"+"2\1"+"subject\1"+"body\1"+"\0\n"));
		
		
		
		
		//add posts
		//should be failed - wrong messages format
		//assertEquals("failed\nadd tpost Msg wrong format\n\0", super.serverParsingTest("addPost\nuser\nsub\nbod\n2\n3\n4\n3\n"));
		//should be failed - wrong number of arguments
		//assertEquals("addPostMessage\nfailed\n\0", super.serverParsingTest("addPost\ntamir\nsport\nbody\n2\n3\n3\n"));
		//should be success "Tamir added a thread message in *** thats 3rd argument (1)
		//assertEquals("addPostMessage\nsuccess\n\0", super.serverParsingTest("addPost\ntamir\nsport\nbody\n2\n1\n1\n"));
		
		//view thread message
		//wrong number of arguments should be failed
		//assertEquals("wrong format ViewSubForumMessage\n\0", super.serverParsingTest("viewThread\n1\n2\n3\n"));
		//should be success
		//assertEquals("postList\n1:sub\nbod\n3:sport\nbody\n\0", super.serverParsingTest("viewThread\n2\n1\n"));

	}
}

